package cz.semjob.learning.instances;

import java.util.List;

import cz.semjob.document.annotation.RelationWordsPair;
import cz.semjob.document.processing.DocumentInstance;
import cz.semjob.learning.data.attribute.AInstanceAttribute;

public class UnlabeledRelationInstance extends UnlabeledTextInstance {

	private RelationWordsPair relationWordsPair;

	public UnlabeledRelationInstance(List<AInstanceAttribute> attributesList,
			DocumentInstance documentInstance) {
		super(attributesList, documentInstance);
	}

	public void setExpressions(LabeledTextInstance expression1textInstance,
			LabeledTextInstance expression2textInstance) {
		this.relationWordsPair = new RelationWordsPair(
				expression1textInstance.words, expression2textInstance.words,
				expression1textInstance.getLabel(),
				expression2textInstance.getLabel());
		for (String attributeName : expression1textInstance
				.getAttributeValues().keySet()) {
			this.attributeValues.put(
					"Expression1" + attributeName,
					expression1textInstance.getAttributeValues().get(
							attributeName));
		}
		for (String attributeName : expression2textInstance
				.getAttributeValues().keySet()) {
			this.attributeValues.put(
					"Expression2" + attributeName,
					expression2textInstance.getAttributeValues().get(
							attributeName));
		}
	}

	public RelationWordsPair getRelationWordsPair() {
		return relationWordsPair;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime
				* result
				+ ((relationWordsPair == null) ? 0 : relationWordsPair
						.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		UnlabeledRelationInstance other = (UnlabeledRelationInstance) obj;
		if (relationWordsPair == null) {
			if (other.relationWordsPair != null)
				return false;
		} else if (!relationWordsPair.equals(other.relationWordsPair))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "UnlabeledRelationInstance [relationWordsPair="
				+ relationWordsPair + "]";
	}

}
